package com.vdimitr.happycube.puzzle.piece;

/**
 * This class denotes how many times a puzzle piece is rotated. It is also
 * responsible for getting the next or previous rotation based on the current
 * rotation.
 * 
 * @author vasileios.dimitriadis
 * 
 */
public enum PuzzlePieceRotation {

	NONE(0), ONCE(1), TWICE(2), THRICE(3);

	private int rotationCount;

	public int getRotationCount() {
		return this.rotationCount;
	}

	/**
	 * Increases the rotation by one. If rotation is THRICE then goes to NONE.
	 * 
	 * @return the next rotation
	 */
	public PuzzlePieceRotation next() {
		PuzzlePieceRotation nextRotation = null;
		switch (this) {
		case NONE:
			nextRotation = PuzzlePieceRotation.ONCE;
			break;
		case ONCE:
			nextRotation = PuzzlePieceRotation.TWICE;
			break;
		case TWICE:
			nextRotation = PuzzlePieceRotation.THRICE;
			break;
		case THRICE:
			nextRotation = PuzzlePieceRotation.NONE;
			break;
		}
		return nextRotation;
	}

	/**
	 * Decreases the rotation by one. If rotation is NONE then goes to THRICE.
	 * 
	 * @return the previous rotation
	 */
	public PuzzlePieceRotation previous() {
		PuzzlePieceRotation nextRotation = null;
		switch (this) {
		case NONE:
			nextRotation = PuzzlePieceRotation.THRICE;
			break;
		case ONCE:
			nextRotation = PuzzlePieceRotation.NONE;
			break;
		case TWICE:
			nextRotation = PuzzlePieceRotation.ONCE;
			break;
		case THRICE:
			nextRotation = PuzzlePieceRotation.TWICE;
			break;
		}
		return nextRotation;
	}

	private PuzzlePieceRotation(int rotationCount) {
		this.rotationCount = rotationCount;
	}
}
